package com.sl.demo.service;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.sl.demo.dao.UserDao;
import com.sl.demo.entity.User;

@Service
public class UserService {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Autowired
	 private UserDao userDao;
	
	public void createUser(String name, Integer age){
		System.out.println("createUser");
		jdbcTemplate.update("insert into users(id,name,age) value(?,?,?);", 100,name, age);
		System.out.println("创建用户成功...");
	}
	
	public User findUser(Integer id) {
		System.out.println("findUser,id="+id);
		User findOne = userDao.getOne(id);
		System.out.println("findUser,id="+id+",user="+findOne);
		return findOne;
	}
	
	public User findUserByName(String name) {
		System.out.println("findUser,name="+name);
		User findOne = userDao.findByName(name);
		System.out.println("findUser,name="+name+",user="+findOne);
		
		return findOne;
	}

}
